from django.shortcuts import render,redirect
from django.core.urlresolvers import reverse
from .functions import *
from stories.models import *



# 主页
def index(request):
    try:
        # 从数据库中获取首页活动中广告图片
        ads = ActiveImage.objects.get_ads()

        # 从数据库中获取菜品分类
        dish_classify = DishClassify.objects.get_dish_classify()

        # 获取热门菜品四个
        dish_hot_4 = Dishes.objects.get_dish_hot_4()

        # 获取最热门三个故事
        story_hot_3 = Story.objects.get_story_hot_3()
        story1 = story_hot_3[0]
        story2 = story_hot_3[1]
        story3 = story_hot_3[2]

    except:
        pass

    return render(request, 'index/index.html', locals())

def homepage(request):
    return redirect(reverse("index:index"))
